﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using PPIDataAccess.General;

namespace PPIDataAccess.Data
{
    public static class DVendor_Project
    {
        #region Query

        public static DataSet SelectData(Int32 Vendor_ProjectID, string connectionKey)
        {
            SqlDataAdapter da = null;
            try
            {
                da = new SqlDataAdapter("up_Vendor_Projects_SelectData", DBHelper.GetConnection(connectionKey));
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Vendor_ProjectID", ParameterDirection.Input, false, Vendor_ProjectID));
                DataSet ds = new DataSet();
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count == 1)
                    return ds;
                else
                    return null;
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing up_Vendor_Projects_SelectData", ex);
            }
            finally
            {
                if (da != null) da.SelectCommand.Connection.Close();
            }
        
        }

        public static DataSet SelectAll(string connectionKey)
        {
            SqlDataAdapter da = null;
            try
            {
                da = new SqlDataAdapter("up_Vendor_Projects_SelectAll", DBHelper.GetConnection(connectionKey));
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing up_Vendor_Projects_SelectAll", ex);
            }
            finally
            {
                if (da != null) da.SelectCommand.Connection.Close();
            }

        }

        public static DataSet SelectAllIdName(string connectionKey)
        {
            SqlDataAdapter da = null;
            try
            {
                da = new SqlDataAdapter("up_Vendor_Projects_SelectAllIdName", DBHelper.GetConnection(connectionKey));
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing up_Vendor_Projects_SelectAllIdName", ex);
            }
            finally
            {
                if (da != null) da.SelectCommand.Connection.Close();
            }
        }

        public static DataSet SelectAllIdNameByVendor(int vendorID, string connectionKey)
        {
            SqlDataAdapter da = null;
            try
            {
                da = new SqlDataAdapter("up_Vendor_Projects_SelectAllIdNameByVendor", DBHelper.GetConnection(connectionKey));
                da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@VendorID", ParameterDirection.Input, false, vendorID));
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing up_Vendor_Projects_SelectAllIdNameByVendor", ex);
            }
            finally
            {
                if (da != null) da.SelectCommand.Connection.Close();
            }
        }



        #endregion
    }
}
